<?php
namespace app\components;

use Yii;

/**
 *
 */
class Controller extends \yii\web\Controller
{
    public function beforeAction($action)
    {
            $session = Yii::$app->session;
            $session->open();
            if (!isset($session['language'])) 
            {
                $langn = 'zh-cn';
                //$session['language'] = strtolower(str_replace('-', '_', $lang[0]));
                $lang = strtolower($langn[0]);
                if($lang == 'zh-cn')
                {
                    $session['language'] = 'zh-CN';
                }
                elseif($lang == 'en-us')
                {
                    $session['language'] = 'en-US';
                }
                else
                {
                    $session['language'] = $langn;
                }
                Yii::$app->language = $session['language'];
            }
            else
            {
                Yii::$app->language = $session['language'];
            }
            return parent::beforeAction($action);
    }
}
?>
